let location = {}

/**
 * 打开内置地图
 * @date 2022-09-21
 */
location.openLocation = function(lat, lng, name = '', address = '') {
	return new Promise((resolve, reject) => {
		uni.openLocation({
			latitude: Number(lat),
			longitude: Number(lng),
			name: name,
			address: address,
			success: (res) => {
				console.log('openLocationSuccess', res)
				resolve(res)
			},
			fail: (res) => {
				console.log('openLocationFail', res)
				reject(res)
			},
			complete: (res) => {
				console.log('openLocationComplete', res)
			},
		})
	})
}

/**
 * 获取当前的地理位置、速度
 * @date 2022-11-17
 */
location.getLocation = function() {
	return new Promise((resolve, reject) => {
		uni.getLocation({
			type: 'wgs84',
			success: (res) => {
				console.log('getLocationSuccess', res)
				resolve({
					lng: res.longitude,
					lat: res.latitude
				})
			},
			fail: (res) => {
				console.log('getLocationFail', res)
				reject(res)
			},
			complete: (res) => {
				// console.log('getLocationComplete', res)
			}
		})
	})
}


export default location
